# -*- coding: utf-8 -*-
"""
@Time: 2022/3/18 08:46
@Author: jins
@File: table_ods_device_electric_ts.py
@Introduction: 
"""
import time

from common.mysqlDataOperate import OperateMysql
from datetime import datetime, timedelta
from threading import Thread
import random


def insert(start_device_id, step):
    for j in range(0, step):
        print(start_device_id)
        # om = OperateMysql(database='xlcloud', host='192.168.0.172', port=8069, user='xlsoft',
        #                   password='xlsoft1!')
        om = OperateMysql(version=221)
        data_time = datetime(2022, 4, 1, 0, 0)
        for _ in range(96 * 5):
            sql = f"""INSERT INTO data_center.ods_device_electric_ts222
            VALUES
            	(
            		{start_device_id},
            		'{data_time}',
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1.234,
            		1,
            		1,
            		'{data_time.timestamp()}',
            	15 
            	)"""
            data_time += timedelta(minutes=15)
            om.batch_excute(sql)
        om.commit()
        om.close()
        start_device_id += 1


if __name__ == '__main__':
    # start_time = time.time()
    # insert(1000004, 4)
    # end_time = time.time()
    # res = end_time - start_time
    # print(res)
    start_time = time.time()
    list_device = [i for i in range(10000000, 10000005) if i % 1 == 0]
    print(list_device)
    thread_list = []
    for i in list_device:
        t = Thread(target=insert, args=(i, 1))
        t.start()
        thread_list.append(t)
    for i in thread_list:
        i.join()
    end_time = time.time()
    res = end_time - start_time
    print(res)
    # om = OperateMysql(database='xlcloud', host='192.168.0.172', port=8069, user='xlsoft',
    #                   password='xlsoft1!')
    # res = om.excute_sql(sql=f"""select * from ods_device_electric_ts221""")
    # print(res)
